package com.leo.ui;

import com.almasb.fxgl.app.scene.FXGLMenu;
import com.almasb.fxgl.app.scene.MenuType;
import com.almasb.fxgl.dsl.FXGL;
import javafx.animation.TranslateTransition;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.layout.VBox;
import javafx.util.Duration;

/**
 * @Author: wangss
 * @CreateTime: 2023-06-13  21:57
 * @Description: 自定义主菜单
 */
public class TestMainMenu extends FXGLMenu {

    private final VBox box;
    private final TranslateTransition tt;

    public TestMainMenu() {
        super(MenuType.MAIN_MENU);

        Button button1 = new Button("开始游戏");
        button1.setOnAction(event -> FXGL.getGameController().startNewGame());
        Button button2 = new Button("设置");
        button2.setOnAction(event -> getController().gotoMainMenu());
        Button button3 = new Button("退出");
        button3.setOnAction(event -> getController().exit());
        Button button4 = new Button("其他");
        button4.setOnAction(event -> new Alert(Alert.AlertType.INFORMATION).showAndWait());

        box = new VBox();
        box.setSpacing(10);
        box.getChildren().addAll(button1, button2, button3, button4);

        getContentRoot().getChildren().add(box);
        // 动画效果
        tt = new TranslateTransition(Duration.seconds(1), box);
        tt.setFromX(0);
        tt.setToX(300);

    }

    @Override
    public void onCreate() {
        tt.play();
    }
}
